var mutex;
var tabProcess = new Array;
var tabMinorProcess = new Array;
window.setInterval("excuteProcess()", 50);

function addToStackMinorProcess(process) {
	if (!isInMinorQueue(process)) {
		tabMinorProcess.push(process);
	}

}
function addToStackProcess(process) {
	
	if (!isInQueue(process)) {
		tabProcess.push(process);
	}
}

function isInQueue(process) {
	for (i = 0; i < tabProcess.length; ++i) {
		if (tabProcess[i] == process) {

			return true;
		}
	}
	return false;
}

function isInMinorQueue(process) {
	for (i = 0; i < tabMinorProcess.length; ++i) {
		if (tabMinorProcess[i] == process) {

			return true;
		}
	}
	return false;
}

function excuteProcess() {
	noMajorProcess=true;
	if (tabProcess instanceof Array) {
		if (tabProcess.length > 0) {
			if (typeof tabProcess[tabProcess.length - 1] !== "undefined") {
				process = tabProcess[tabProcess.length - 1];
				tabProcess.pop();
				window[process]();
				noMajorProcess=false;
			}

		}
	} 
	if(noMajorProcess) {
		tabProcess = new Array;
		if (tabMinorProcess instanceof Array) {
			if (tabMinorProcess.length > 0) {
				if (typeof tabMinorProcess[tabMinorProcess.length - 1] !== "undefined") {
					process = tabMinorProcess[tabMinorProcess.length - 1];
					tabMinorProcess.pop();
					window[process]();
				}

			}
		} else {
			tabProcess = new Array;
		}
	}
}


